<html>
	<head>
		<title>Benvenuto su Multihands</title>
        <link href="css/style.css" rel="stylesheet" type="text/css">
		<script type="text/javascript">
			(function(){
                if( window.localStorage ){
                    if( !localStorage.getItem( 'firstLoad' ) ){
                        localStorage[ 'firstLoad' ] = true;
                        window.location.reload();
                    }
                    else
                        localStorage.removeItem( 'firstLoad' );
                }
            })();
            function check (){
            	var x=document.getElementById("doc");
            	//alert(x.value.search(/[\&\@\,]/)); 
            	//          / , * . _ \ | [] {} - + (carattere di spazio) '' ""
            	if (x.value.length == 0){
            		alert('Devi inserire un nome, oppure clicca su un documento gia creato');
            	}
            	else if (x.value.length > 245){
            		alert("Il nome non puo' essere piu' lungo di 245 caratteri");
            	}
            	else {
            		if (x.value.search(/[\/\,\*\._\\\|\[\]{}\s+\@\#\$\^\&\'\"\(\)]/) != -1 ){
            			alert('Carattere vietato!');
            			x.value = "";
            		}
                    else if (x.value.search(/null/i) != -1 ){
                        alert("Il nome del documento non puo' essere uguale a null");
                        x.value = "";
                    }
            		else {
            			//alert('possiamo partire');
                        document.getElementById("goEditor").submit();
                        x.disabled = true;
                        document.getElementById("invio").disabled = true;
            			// var form = document.createElement('form');
            			// form.method='get';
               //  		form.action='/editor.html';
               //          form.style.visibility="hidden"
               //  		form.appendChild(x);
               //          document.body.appendChild(form);
               //  		form.submit();
            		}
            	}
            }
            function keyPress(e){
            	if (!e) e = window.event; // needed for cross browser compatibility
            	//alert(e.keyCode); // You want 13 here , so 
 				if (e.keyCode == 13) {
 					check();
 				}
 				//  etc..

				// return true; or false, if you want to cancel event
			}
		</script>
	</head>
	<body>
        <div class="wrapper">
            <div class="page">
                <div class="main-container col1-layout">
                    <div class="header-container"> </div>
                    <div class="main">
                        <div class="col-main">
                            <div class ='std'>
                                {{#each documents}}
                                    <p>
                                        <a href="/editor.html?titolo={{this}}">
                                            {{this}}
                                        </a>
                                    </p>
                                {{/each}}
                                <form id="goEditor" method='get' action='/editor.html' onsubmit="check()">
                                    Nome documento <input id="doc" type="text" name="titolo" onkeydown="keyPress()" />
                                    <!-- <input type="submit" value="Submit" /> -->
                                    <input type="button" id='invio' value="Submit" onclick="check()" />
                                </form>
                            </div>
                        </div>
                    </div>
                </div>
            </div>     
        </div>
        <div class="footer-container">
            <div class="footer">
                <address>Copyright 2013 Pad company.</address>
            </div>
        </div>
	</body>
</html>	